{%include file="header.html"%}
<style>
td {  font-weight: bold;}
</style>
<body>
<div class="fixed-bar">
  <div class="item-title">
    <h3>设置商品库存</h3>
  </div>
</div>
<div class="fixed_bottom">
  <form method="post" action="nav_list.php" id="aspnetForm" name="form1" enctype="multipart/form-data">
    <div class="active_body" style="display:block;">
      <table style=" width:100%;" cellpadding="0" cellspacing="0" class="table tb-type2">
          <th>选择商品规格</th>
          {%foreach from=$goods_products item=products key=k%}
            <tr>
              <td class="firtd">{%$products.name%}：</td>
              <td>  
                {%foreach from=$products.val item=goods_attr%} 
                    <input class="gg{%$goods_attr.goods_attr_id%}" type="checkbox" name="is_best{%$goods_attr.attr_id%}" onClick="setattr(this,{%$k%},'{%$goods_attr.attr_value%}',{%$goods_attr.goods_attr_id%},{%$goods.goods_id%})" value="{%$goods_attr.goods_attr_id%}"/>&nbsp;{%$goods_attr.attr_value%}&nbsp;&nbsp;&nbsp;&nbsp;
                {%/foreach%}
                <input type="hidden" class="attr_num{%$k%}" value="0" />
              </td>
            </tr>
          {%/foreach%}
      </table>
      <table style=" width:100%;" cellpadding="0" cellspacing="0" border="1" class="table tb-type2">
      	<th colspan="20" align="center" style="background:#E5F6FE;"><span style="color:#000000;">商品名称：{%$goods.goods_name%}&nbsp;&nbsp;&nbsp;&nbsp;货号：{%$goods.goods_sn%}</span></th>
        <tr>
        	{%foreach from=$goods_products item=products%}
            <td>{%$products.name%}</td>
            {%/foreach%}
        	<td width="200">货号</td>
            <td width="200">库存</td>
        </tr>
        <tr class="attr_consx"></tr>
        <!--<tr>
        	{%foreach from=$goods_products item=products%}
            <td>0</td>
            {%/foreach%}
        	<td><input style="height:20px; width:150px;" type="text" name="product_sn[]" /></td>
            <td><input style="height:20px; width:150px;" class="goods_attrtext" type="text" name="product_number[]" /></td>
        </tr>-->
      </table>
      <!--将选中的属性保存-->
      <div class="attr_conc">
      	
      </div>
    </div>
    <div style="text-align:center">
      <div class="style1">&nbsp;</div>
      <div> <a href="JavaScript:void(0);" class="btn" onclick="reset()"><span>重置</span></a> <a href="JavaScript:void(0);" class="btn" onclick="$('#tj').click()"><span>确认提交</span></a> </div>
    </div>
    <input type="reset" id="cz" style="display: none;">
    <input type="submit" id="tj" style="display:none;">
  </form>
</div>

</body>
<script>
/*
 *商品不同属性对应库存配置
*/
function setattr(obj, key, attrval, attrid, goodsid){
	/*取得当前选中的属性*/
	var tt=$(obj).siblings("input[type=checkbox]").is(":checked");
	var num=0;
	if($(obj).is(":checked")){
		num++;
		var str ="<input alt='"+key+"' id='"+attrid+"' value='"+attrval+"' />";
		$(".attr_conc").html(str);
	}
	if(tt){num++;}
	$(obj).siblings("input[class^=attr_num]").val(num);
	var nn=$(obj).parents("tr").siblings().length;
	for(i=0;i<nn;i++){
		var tt=$(".attr_num"+i).val(); 
		//当有属性没有选中的时候
		if(tt<1){var ck=1;}
	}
	//将选中的属性存储
	
	
	//判断是否选中完整规格
	if(ck==1){
		var sms="<tr><td colspan='20'>请选择完整数据！</td></tr>";
		$(".attr_consx").html(sms);
	}else{
		
		$(".attr_consx").html("");
	}
}

</script>
</html>